- return unless @project.feature_available?(:custom_compliance_frameworks)
- user_has_edit_permissions = current_user.can?(:admin_compliance_framework, @project)
- compliance_framework_doc_link = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('user/project/settings/index.md', anchor: 'add-a-compliance-framework-to-a-project') }
- compliance_pipelines_doc_link = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('user/group/compliance_frameworks.md', anchor: 'compliance-pipelines') }
- gitlab_ci_yaml_doc_link = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('ci/yaml/gitlab_ci_yaml.md') }
- namespace_doc_link = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('user/namespace/index.md', anchor: 'types-of-namespaces') }

- if @project.personal?
  %section.settings.compliance-framework.no-animate#js-compliance-framework
    .settings-header
      %h4= _('Compliance framework')
      %p.gl-text-secondary= html_escape(_('Frameworks can not be added to projects in personal namespaces. %{linkStart}What are personal namespaces?%{linkEnd}')) % { linkStart: namespace_doc_link, linkEnd: '</a>'.html_safe }
    .settings-content
- else
  %section.settings.compliance-framework.no-animate#js-compliance-framework{ class: ('expanded' if expanded) }
    .settings-header
      %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only= _('Compliance framework')
      = render Pajamas::ButtonComponent.new(button_options: { class: 'js-settings-toggle' }) do
        = expanded ? _('Collapse') : _('Expand')
      %p.gl-text-secondary= html_escape(_('Select a compliance framework to apply to this project. %{linkStart}How are these added?%{linkEnd}')) % { linkStart: compliance_framework_doc_link, linkEnd: '</a>'.html_safe }

    .settings-content
      - frameworks = @project.root_ancestor.compliance_management_frameworks
      - if frameworks.any?
        - if project_missing_pipeline_yaml?(@project)
          = render Pajamas::AlertComponent.new(title: s_('ComplianceFramework|No pipeline configuration found'),
            variant: :warning,
            dismissible: false,
            alert_options: { class: 'gl-mb-5' }) do |c|
            - c.with_body do
              = html_escape(_('You should add a %{linkStart}.gitlab-ci.yml%{linkEnd} file to this project to avoid pipeline failures. %{compliancePipelineLinkStart}Why?%{compliancePipelineLinkEnd}')) % { linkStart: gitlab_ci_yaml_doc_link, linkEnd: '</a>'.html_safe, compliancePipelineLinkStart: compliance_pipelines_doc_link, compliancePipelineLinkEnd: '</a>'.html_safe }
        = gitlab_ui_form_for @project, html: { multipart: true, class: "compliance-framework-form" }, authenticity_token: true do |f|
          .form-group
            = f.fields_for :compliance_framework_setting, ComplianceManagement::ComplianceFramework::ProjectSettings.new do |cf|
              = cf.label :framework, class: 'gl-font-weight-bold' do
                = _('Compliance framework')
              - if user_has_edit_permissions
                - selected_default_framework = @project.compliance_framework_setting&.compliance_management_framework&.id
                = cf.select :framework, options_for_select(frameworks.map { |fw| [fw.name.truncate(88), fw.id] }, selected_default_framework), { selected: '', prompt: _('Choose your framework'), include_blank: _('None') }, { class: 'form-control gl-form-input-xl', disabled: false }
              - else
                - selected_framework = @project.compliance_framework_setting&.compliance_management_framework&.name&.truncate(88) || _('None')
                = cf.text_field :framework, value: selected_framework, class: 'form-control read-only', disabled: true
                %p.form-text.text-muted
                  = _("Owners can modify this selection.")
          - if user_has_edit_permissions
            = f.submit _('Save changes'), pajamas_button: true
      - else
        #js-project-compliance-framework-empty-state{ data: project_compliance_framework_app_data(@project, user_has_edit_permissions) }
